package com.mingtu.jgspatrol.adapter;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.common.utils.MyUtills;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.bean.AllTrackRecordBean;

public class AllRecordTrackAdapter extends BaseQuickAdapter<AllTrackRecordBean.DataBean.PageBean.ListBean, BaseViewHolder> {

    public AllRecordTrackAdapter() {
        super(R.layout.item_all_track_record);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, AllTrackRecordBean.DataBean.PageBean.ListBean listBean) {
        String taskName = listBean.getTaskName();
        String duration = listBean.getDuration();
        String mileage = listBean.getMileage();
        String beginTime = listBean.getBeginTime();
        String endTime = listBean.getEndTime();
        String name = listBean.getName();

        if (!StringUtils.isEmpty(taskName)) {
            helper.setText(R.id.tv_task_name, "编号：" + taskName);
        }

        if (!StringUtils.isEmpty(name)) {
            helper.setText(R.id.tv_name, name);
        }

        if (!StringUtils.isEmpty(duration)) {

            long d = 0;
            if (duration.indexOf(".") != -1) {
                String array[] = duration.split("\\.");
                d = Long.parseLong(array[0]);
            } else {
                d = Long.parseLong(duration);
            }

            helper.setText(R.id.tv_duration, MyUtills.formatSeconds3(d) + "");
        }

        if (!StringUtils.isEmpty(mileage)) {
            helper.setText(R.id.tv_mileage, mileage + "km");
        }
        if (!StringUtils.isEmpty(beginTime)) {
            helper.setText(R.id.tv_begin_time, beginTime);
        }
        if (!StringUtils.isEmpty(endTime)) {
            helper.setText(R.id.tv_end_time, endTime);
        }
    }
}
